/*********************/
/** ProcessRFIDQuery.java */
/*********************/
package atag.apps.mainApp;

import atag.runtime.DataItem;
import atag.runtime.DataPool;
import atag.runtime.NodeInfo;
import java.util.Hashtable;

public class ProcessRFIDQuery implements Runnable {

	private DataPool m_dataPool;

	private NodeInfo m_myState;

        private final Hashtable lightSettings = new Hashtable();

	/** Creates a new instance of ProcessRFIDQuery */
	public ProcessRFIDQuery(DataPool dp, NodeInfo myconfig) {
		m_dataPool = dp;
		m_myState = myconfig;

		lightSettings.put("FABB26D29000", new Integer(50));
		lightSettings.put("6EA458609000", new Integer(150));
	}

	public void run() {
		/*Checking for each DataItem, to see which one was produced*/
		DataItem t_dataItem;
		if((t_dataItem = m_dataPool.getData(IDConstants.T_PROCESSRFIDQUERY,
			IDConstants.D_RFIDQUERYREQUEST)) != null){
			RFIDQueryRequest recvdRFIDQueryRequest = (RFIDQueryRequest) t_dataItem.core();
			this.handleRFIDQueryRequestProduced(recvdRFIDQueryRequest);
		}
	}

	private void handleRFIDQueryRequestProduced(RFIDQueryRequest r_RFIDQueryRequest) {
       
		int ID = r_RFIDQueryRequest.getID();
                String RFID=r_RFIDQueryRequest.getRFID();
                m_myState.debugPrint("[ProcessRFIDQuery]Got a ID " + ID+
                        " and RFID "+RFID);

                RFIDQueryResponse m_RFIDQueryResponse = new RFIDQueryResponse();
		m_RFIDQueryResponse.setID(this.m_myState.getMyId());
                if (lightSettings.containsKey(RFID))
			m_RFIDQueryResponse.setLightSetting(((Integer)lightSettings.get(RFID)).intValue());
		else
			m_RFIDQueryResponse.setLightSetting(Constants.DEFAULT_SETTING);
                DataItem m_dataitem =
                    new DataItem(IDConstants.D_RFIDQUERYRESPONSE, IDConstants.T_PROCESSRFIDQUERY, m_RFIDQueryResponse);
		m_dataPool.putData(m_dataitem);
		
	}
}
